<template>
  <div>
    <el-select v-model="workshopId" clearable placeholder="请选择生产车间" filterable>
      <el-option v-for="workshop in workshopOptions"
                 :key="workshop.id" :label="workshop.name" :value="workshop.id"/>
    </el-select>
  </div>
</template>

<script>
import { getWorkshopSimple } from "@/api/base/workshop"
export default {
  name: "SelectWorkshop",
  props: {
    value: {
      required: true
    }
  },
  data() {
    return {
      workshopOptions: [],
      workshopId: this.value,
    }
  },
  watch: {
    value(newVal) {
      this.workshopId = newVal;
    },
    workshopId(newVal, oldVal){
      this.$emit("input", this.workshopId)
    }
  },
  created() {
    this.getWorkshopListFun();
  },
  methods: {
    /** 查询工厂列表 */
    getWorkshopListFun(){
      getWorkshopSimple().then(response => {
        this.workshopOptions = response.data;
      })
    },
  }
};
</script>

